package com.seal.yoyoshop.dao.impl;

import com.seal.yoyoshop.bin.Admin;
import com.seal.yoyoshop.dao.AdminDao;
import com.seal.yoyoshop.util.DBUtils;

public class AdminDaoImpl implements AdminDao {
    @Override
    public Admin SelectAdminByUsernameAndPassword(String username, String password) {
        String sql = "SELECT * FROM admin WHERE username = ? AND password = ?";
        Admin admin = DBUtils.queryOne(sql,Admin.class,username,password);
        return admin;
    }

    @Override
    public Admin selectAdminById(Integer id) {
        String sql = "SELECT * FROM admin WHERE id = ?";
        Admin admin = DBUtils.queryOne(sql,Admin.class,id);
        return admin;
    }

    @Override
    public boolean updatePassword(Admin admin) {
        String sql = "UPDATE admin SET password = ? WHERE id = ?";
        int row = DBUtils.update(sql,admin.getPassword(),admin.getId());
        if(row == 1)return true;
        return false;
    }
}
